﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Base.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    TransceiverDetail
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <ext:Viewport ID="ViewPort1" runat="server" Layout="fit">
        <Items>
            <ext:GridPanel ID="GridPanel1" runat="server" Header="false" Border="false" TrackMouseOver="true"
                SkipIdForNewRecords="true" Layout="FitLayout">
                <Store>
                    <ext:Store ID="dcTransceiver" runat="server" AutoSave="false">
                        <Proxy>
                            <ext:HttpProxy Url="/Transceiver/GetTransceiverDetailStore/" />
                        </Proxy>
                        <UpdateProxy>
                            <ext:HttpWriteProxy Url="/Transceiver/SaveTransceiverWithConfirmation/" />
                        </UpdateProxy>
                        <BaseParams>
                            <ext:Parameter Name="userid" Value="_userid" Mode="Raw" />
                            <ext:Parameter Name="transceiverdate" Value="_transceiverdate" Mode="Raw" />
                        </BaseParams>
                        <Reader>
                            <ext:JsonReader IDProperty="id" Root="data" TotalProperty="total" MessageProperty="message">
                                <Fields>
                                    <ext:RecordField Name="id" />
                                    <ext:RecordField Name="to" />
                                    <ext:RecordField Name="count" />
                                    <ext:RecordField Name="date" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <SortInfo Field="date" Direction="DESC" />
                        <Listeners>
                            <Exception Handler="
                                Ext.net.Notification.show({
                                    iconCls   : 'icon-exclamation', 
                                    html      : e && e.message ? e.message : response.message || response.statusText, 
                                    title     : '出错啦', 
                                    hideDelay : 5000
                                });" />
                            <Save Handler="
                                Ext.net.Notification.show({
                                    iconCls   : 'icon-information', 
                                    html      : '保存记录成功', 
                                    title     : '保存成功', 
                                    hideDelay : 5000
                                });
                                parent.dcTransceiver.reload();" />
                        </Listeners>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="ID" DataIndex="ID" Header="ID" Hidden="true">
                            <Editor>
                                <ext:DisplayField ID="DisplayField1" runat="server" StyleSpec="padding-left:5px;font:12px arial, tahoma, helvetica, sans-serif;" />
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="tto" DataIndex="to" Header="发出到" Width="200">
                            <Editor>
                                <ext:SelectBox ID="sltTo" runat="server" AllowBlank="false" DisplayField="text" ValueField="value"
                                    EmptyText="请选择一个发送组">
                                    <Store>
                                        <ext:Store runat="server" ID="StoreBusiness">
                                            <Proxy>
                                                <ext:HttpProxy runat="server" Url="/Setting/TransceiverTo.xml" />
                                            </Proxy>
                                            <Reader>
                                                <ext:XmlReader Record="item">
                                                    <Fields>
                                                        <ext:RecordField Name="value" Mapping="@value" />
                                                        <ext:RecordField Name="text" Mapping="@text" />
                                                    </Fields>
                                                </ext:XmlReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                    <Listeners>
                                        <Select Fn="afterTransceiverToSelect" />
                                    </Listeners>
                                </ext:SelectBox>
                                <%--<ext:DisplayField ID="dpBusiness" runat="server" DataIndex="Business"></ext:DisplayField>--%>
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="count" DataIndex="count" Header="数量" Width="200">
                            <Editor>
                                <ext:NumberField ID="NumberField1" runat="server" SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="btnSave" runat="server" Text="保存" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{dcTransceiver}.save();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="btnAdd" runat="server" Text="添加" Icon="Add">
                                <Listeners>
                                    <Click Handler="#{GridPanel1}.insertRecord(0,{date:(new Date()).format('Y-m-d'),to:'',count:0,UserID:'',id:''});#{GridPanel1}.getView().focusRow(0);#{GridPanel1}.getRowEditor().startEditing(0);" />
                                </Listeners>
                            </ext:Button>
                            <%--<ext:Button ID="Button2" runat="server" Text="Reject Changes" Icon="ArrowUndo">
                                <Listeners>
                                    <Click Handler="#{dcTransceiver}.rejectChanges();" />
                                </Listeners>
                            </ext:Button>--%>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Plugins>
                    <ext:RowEditor ID="RowEditor" runat="server" ErrorSummary="false" ClicksToEdit="1"
                        CancelText="取消" SaveText="确认">
                        <Listeners>
                            <BeforeEdit Fn="setRowEditorState" />
                            <CancelEdit Fn="rowCancelEdit" />
                        </Listeners>
                    </ext:RowEditor>
                </Plugins>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderArea" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="StartupArea" runat="server">
    <script type="text/javascript">
        var _userid = '<%=ViewData("UserID") %>';
        var _transceiverdate = '<%=ViewData("TransceiverDate") %>';

        var setRowEditorState = function (el, rowIndex) {
            var cd = new Date(_transceiverdate);
            var td = new Date();
            if (cd.format('Y-m-d') != td.format('Y-m-d')) {
                return false;
            } else {
                //                if (GridPanel1.store.data.items[rowIndex].data['to'] != "") {
                //                    sltBusiness.disabled = true;
                //                } else {
                //                    sltBusiness.disabled = false;
                //                }
            }
        }

        var rowCancelEdit = function (el, forced) {
            if (GridPanel1.store.data.items[0].data['to'] == "") {
                GridPanel1.store.remove(GridPanel1.store.data.items[0]);
            }
        }

        var afterTransceiverToSelect = function (item, record, index) {
            var odata = GridPanel1.store.data;
            for (i = 0; i < GridPanel1.store.data.items.length; i++) {
                if (GridPanel1.store.data.items[i].data['to'] == record.data.value) {
                    Ext.Msg.show({
                        title: 'DailyReport',
                        buttons: { yes: '确认' },
                        msg: '列表中已包含相同的组。',
                        fn: function (btn) {
                            item.clear();
                            return false;
                        }
                    });

                }
            }
        }

        Ext.onReady(function () {
            var cd = new Date(_transceiverdate);
            var td = new Date();

            if (cd.format('Y-m-d') != td.format('Y-m-d')) {
                btnSave.hide();
                btnAdd.hide();
            }
        });
    </script>
</asp:Content>
